package com.inspire.springboot.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ：inspire
 * @date ：Created in 2022/11/15 15:24
 * @description：
 * @modified By：inspire
 * @version:
 */
public class DBConvertUtil {
    public static Timestamp changeDate(String date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Timestamp ts = null;
        try {
            Date parse = sdf.parse(date);
            ts = new Timestamp(parse.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return ts;
    }

    public static java.sql.Date strToDate(String strDate) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date d = null;
        try {
            d = format.parse(strDate);
        } catch (Exception e) {
            e.printStackTrace();
        }
        java.sql.Date date = new java.sql.Date(d.getTime());
        return date;
    }
}
